import { isNullOrUndefined, isNullOrUndefinedOrEmptyString } from '../string/string-utils';

export function isDevEnv(): boolean {
  return import.meta.env.DEV;
}

/**
 * Executes the function by using its name.
 * @param scope The function scope instance.
 * @param fnName The string of the function name.
 * @param param The parameter that the function might accept.
 * @returns Any data might be returned by this function.
 */
export function executeFunctionByName(scope: any, fnName: string, param?: any): any {
  if (!isNullOrUndefined(scope) && !isNullOrUndefinedOrEmptyString(fnName)) {
    return scope[fnName](param);
  } else {
    return null;
  }
}

/**
 * Delays execution for specific millionseconds.
 */
export function delay(ms: number): Promise<number> {
  return new Promise((resolve) => setTimeout(resolve, ms));
}
